package com.app.server.impl;

import com.app.mapper.EmergentContactMapper;
import com.app.model.EmergentContactModel;
import com.app.model.PopularScienceModel;
import com.app.server.EmergentContactService;
import com.app.utils.StringTool;
import com.app.vo.EmergentContactVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmergentContactServiceImpl extends ServiceImpl<EmergentContactMapper, EmergentContactModel> implements EmergentContactService{
    @Autowired
    private EmergentContactMapper emergentContactMapper;
    //分页查询紧急联系
    @Override
    public EmergentContactVo getEmergentList(Integer page, Integer limit,String name) {
        Page<EmergentContactModel> page1 = new Page<>(page, limit);
        QueryWrapper<EmergentContactModel> qw =new QueryWrapper<>();
        if (StringTool.isNotEmpty(name)){
            qw.like("name",name);
        }
        qw.orderByDesc("id");
        Page<EmergentContactModel> emergentPage = emergentContactMapper.selectPage(page1, qw);
        List<EmergentContactModel> emergentList = emergentPage.getRecords();

        long count = emergentPage.getTotal();
        EmergentContactVo emergentContactVo = new EmergentContactVo();
        emergentContactVo.setList(emergentList);
        emergentContactVo.setCount((int) count);
        return emergentContactVo;
    }
}
